class Solution(object):
    def findRestaurant(self, list1, list2):
        """
        :type list1: List[str]
        :type list2: List[str]
        :rtype: List[str]
        """
        s1 = {name: i for i, name in enumerate(list1)}
        min_len = float('inf')
        out = []
        for j, name in enumerate(list2):
            if name in s1:
                if s1[name] + j < min_len:
                    min_len = s1[name] + j
                    out = [name]
                else:
                    if s1[name] + j == min_len:
                        out.append(name)
        return out